/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.tukano.io;

import java.nio.ByteBuffer;

/**
 *
 * @author utente4
 */
public class ByteBufferExt {
    
    public static ByteBufferExt wrap(ByteBuffer buffer) {
        return new ByteBufferExt(buffer);
    }
    private final ByteBuffer buffer;

    private ByteBufferExt(ByteBuffer buffer) {
        this.buffer = buffer;
    }
    
    public ByteBufferExt setCursorPosition(int p) {
        buffer.position(p);
        return this;
    }
    
    public boolean hexMatches(String... hexBytes) {
        for (int i = 0; i < hexBytes.length; i++) {
            String string = hexBytes[i].toLowerCase();;
            if(!buffer.hasRemaining()) return false;
            byte b = buffer.get();
            if(!string.startsWith("0x")) {
                string = "0x" + string;
            }
            byte that = Byte.decode(string);
            if(b != that) return false;
        }
        return true;
    }

    public ByteBufferExt skip(int i) {
        buffer.position(buffer.position() + i);
        return this;
    }

    public int getInt() {
        return buffer.getInt();
    }
}
